package com.dgut.demo.controller;

import com.dgut.demo.bean.PurchaseMessage;
import com.dgut.demo.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/2/23 21:16
 * @Version 1.0
 */
@RestController
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    @GetMapping("/getAllPurchaseMessage")
    public List<PurchaseMessage> getAllPurchaseMessage(){
        return purchaseService.getAllPurchaseMessage();
    }

    @GetMapping("/getPurchaseMessageByPid")
    public List<PurchaseMessage> getPurchaseMessageByPid(String pid){
        return purchaseService.getPurchaseMessageByPid(pid);
    }

    @GetMapping("/getPurchaseMessageByPsid")
    public List<PurchaseMessage> getPurchaseMessageByPsid(String psid){
        return purchaseService.getPurchaseMessageByPsid(psid);
    }

    @GetMapping("/getPurchaseMessageByEname")
    public List<PurchaseMessage> getPurchaseMessageByEname(String ename){
        return purchaseService.getPurchaseMessageByEname(ename);
    }

    @GetMapping("/getPurchaseMessageByMaterial")
    public List<PurchaseMessage> getPurchaseMessageByMaterial(String material){
        return purchaseService.getPurchaseMessageByMaterial(material);
    }

    @PostMapping("/addOnePurchaseMessage")
    public int addOnePurchaseMessage(String psid,String peid,int pcounts){
        System.out.println(peid);
        PurchaseMessage purchaseMessage = new PurchaseMessage();
        purchaseMessage.setPcounts(pcounts);
        purchaseMessage.setPeid(peid);
        purchaseMessage.setPsid(psid);
        return purchaseService.addOnePurchaseMessage(purchaseMessage);
    }
}
